package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MaterialResidue;
import com.ruoyi.system.service.IMaterialResidueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中央仓库剩余量Controller
 *
 * @author Naruto
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/system/residue")
public class MaterialResidueController extends BaseController {
    @Autowired
    private IMaterialResidueService materialResidueService;

    /**
     * 查询中央仓库剩余量列表
     */
    @PreAuthorize("@ss.hasPermi('system:residue:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialResidue materialResidue) {
        startPage();
        List<MaterialResidue> list = materialResidueService.selectMaterialResidueList(materialResidue);
        return getDataTable(list);
    }

    /**
     * 导出中央仓库剩余量列表
     */
    @PreAuthorize("@ss.hasPermi('system:residue:export')")
    @Log(title = "中央仓库剩余量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialResidue materialResidue) {
        List<MaterialResidue> list = materialResidueService.selectMaterialResidueList(materialResidue);
        ExcelUtil<MaterialResidue> util = new ExcelUtil<MaterialResidue>(MaterialResidue.class);
        util.exportExcel(response, list, "中央仓库剩余量数据");
    }

    /**
     * 获取中央仓库剩余量详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:residue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(materialResidueService.selectMaterialResidueById(id));
    }

    /**
     * 新增中央仓库剩余量
     */
    @PreAuthorize("@ss.hasPermi('system:residue:add')")
    @Log(title = "中央仓库剩余量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialResidue materialResidue) {
        return toAjax(materialResidueService.insertMaterialResidue(materialResidue));
    }

    /**
     * 修改中央仓库剩余量
     */
    @PreAuthorize("@ss.hasPermi('system:residue:edit')")
    @Log(title = "中央仓库剩余量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialResidue materialResidue) {
        return toAjax(materialResidueService.updateMaterialResidue(materialResidue));
    }

    /**
     * 删除中央仓库剩余量
     */
    @PreAuthorize("@ss.hasPermi('system:residue:remove')")
    @Log(title = "中央仓库剩余量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialResidueService.deleteMaterialResidueByIds(ids));
    }
}
